const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
//  自定义插件
const FileListPlugin = require('./plugins/index');
const RMLogs = require('./plugins/removeLog');
module.exports = {
  entry: './src/index/index.js',
  output: {
    filename: 'index.min.js',
    path: path.resolve(__dirname, 'dist'),
    libraryTarget: 'umd'
  },
  plugins: [
    //插进的引用, 压缩，分离美化
    new HtmlWebpackPlugin({
      //将模板的头部和尾部添加css和js模板,dist 目录发布到服务器上，项目包。可以直接上线
      filename: './index_bundle.html', //打造单页面运用 最后运行的不是这个
      template: './src/index/index.html'
    }),
    // new ExtractTextPlugin('./index.css'),
    new FileListPlugin({ option: 'hello' }),
    new RMLogs({ options: true })
  ],
  module: {
    rules: [
      // 自定义loader
      {
        test: /\.md$/,
        exclude: /node_modules/,
        loader: path.resolve(__dirname, 'loader/index.js')
      },
      {
        test: /\.less$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: ['css-loader', 'less-loader']
        })
      },
      // 处理图片
      {
        test: /\.(jpg|gif|png)$/,
        use: [
          {
            loader: 'file-loader',
            options: {
              outputPath: 'img'
            }
          }
        ]
      },
      {
        test: /\.js$/,
        include: [path.resolve(__dirname, 'src')],
        loader: 'babel-loader'
      }
    ]
  }
};
